package com.voodoo.lib_utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.TelephonyManager;

import java.lang.reflect.Method;

import static android.content.Context.TELEPHONY_SERVICE;

/**
 * Author：voodoo
 * CreateTime：2021/07/16 016 下午 01:54
 * Description：设备工具类
 */
public class DeviceUtils {

    /**
     * 获取机器SN
     *
     * @return 机器sn
     */
    public static String getDeviceSn() {
        String serial = null;
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            serial = (String) get.invoke(c, "ro.serialno");
        } catch (Exception e) {
            e.printStackTrace();
        }//O6Q74OYPER  RKAC1SCOPAS8AEF824508I0
        return BuildConfig.DEBUG ? "003001314210b188e37b" : serial;
    }

    /**
     * 获取SIM卡卡号
     *
     * @param context 上下文，建议使用Application
     * @return 手机卡背后20位卡号
     */
    @SuppressLint({"MissingPermission", "HardwareIds"})
    public static String getSimSerialNumber(Context context) {
        TelephonyManager telMgr = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
        return telMgr.getSimSerialNumber();
    }

}
